package roomServlet;

import javaBean.roomDTO;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class showRoom {
    public List showRoom() {
        List<roomDTO> list = new ArrayList<roomDTO>();

        java.sql.Connection conn = null;
        java.sql.Statement sqlStmt = null;
        ResultSet rs = null;
        try {
            Class.forName("org.h2.Driver");
            conn = java.sql.DriverManager.getConnection("jdbc:h2:~/jpa-demo-db;MODE=MYSQL;DB_CLOSE_DELAY=-1", "sa", "sa");
            sqlStmt = conn.createStatement();

            rs = sqlStmt.executeQuery("select * from room");//选择import java.sql.ResultSet

            while (rs.next()) {
                roomDTO roomdto = new roomDTO();
                roomdto.setRoom_number(rs.getString(1));
                roomdto.setRoom_status(rs.getString(2));
                roomdto.setRoom_style(rs.getString(3));
                roomdto.setRoom_price(rs.getInt(4));
                list.add(roomdto);
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
        return list;
    }
}
